home *** CD-ROM | disk | FTP | other *** search
/ Mac Format 1994 October / Macformat17.cdr / Shareware City / Developers / shutdown-fx-201-c / sfx ƒ / sfx control app ƒ / sfx code ƒ / sfx lists.c < prev    next >
Text File  |  1994-07-11  |  5KB  |  188 lines

  1. /**********************************************************************\
  2.  
  3. File:        sfx lists.c
  4.  
  5. Purpose:    This module handles anything and everything about lists:
  6.             initializing, drawing, scrolling, clicking, etc.
  7.  
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12.  
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with this program in a file named "GNU General Public License".
  20. If not, write to the Free Software Foundation, 675 Mass Ave,
  21. Cambridge, MA 02139, USA.
  22.  
  23. \**********************************************************************/
  24.  
  25. #include "sfx lists.h"
  26. #include "sfx meat.h"
  27. #include "error.h"
  28.  
  29. #define kTextLDEF        0        /* default LDEF */
  30. #define kDoDraw            TRUE    /* always draw list after changes */
  31. #define kNoGrow            FALSE    /* don't leave room for size box */
  32. #define kIncludeScroll    TRUE    /* leave room for scroll bar */
  33. #define kScrollWidth    15        /* width of scroll bar */
  34.  
  35. ListHandle MyCreateVerticalScrollingList(WindowPtr theWindow, Rect boundsRect,
  36.     short columnsInList, short theLDEF)
  37. {
  38.     Rect            dataBoundsRect;
  39.     Point            cellSize;
  40.     
  41.     SetRect(&dataBoundsRect, 0, 0, columnsInList, 0);
  42.     SetPt(&cellSize, 0, 0);
  43.     boundsRect.right=boundsRect.right-kScrollWidth;
  44.     return LNew(&boundsRect, &dataBoundsRect, cellSize, theLDEF, theWindow, kDoDraw,
  45.         kNoGrow, !kIncludeScroll, kIncludeScroll);
  46. }
  47.  
  48. void MyDrawListBorder(ListHandle theList)
  49. {
  50.     Rect            theBorder;
  51.     PenState        thePenState;
  52.     
  53.     theBorder=(**theList).rView;
  54.     GetPenState(&thePenState);
  55.     PenSize(1,1);
  56.     InsetRect(&theBorder, -1, -1);
  57.     FrameRect(&theBorder);
  58.     SetPenState(&thePenState);
  59. }
  60.  
  61. void MyDrawActiveListBorder(ListHandle theList, Boolean isActive)
  62. {
  63.     Rect            outlineRect;
  64.     PenState        thePenState;
  65.     
  66.     outlineRect=(**theList).rView;
  67.     if (((**theList).vScroll)!=0L)
  68.         outlineRect.right+=kScrollWidth;
  69.     if (((**theList).hScroll)!=0L)
  70.         outlineRect.bottom+=kScrollWidth;
  71.     SetPort((**theList).port);
  72.     InsetRect(&outlineRect, -4, -4);
  73.     GetPenState(&thePenState);
  74.     if ((isActive) && ((**theList).lActive))
  75.         PenPat(black);
  76.     else
  77.         PenPat(white);
  78.     PenSize(2,2);
  79.     FrameRect(&outlineRect);
  80.     SetPenState(&thePenState);
  81. }
  82.  
  83. void MyAddStr255ToList(ListHandle theList, Str255 theStr)
  84. {
  85.     short            rowNum;
  86.     Cell            theCell;
  87.     
  88.     rowNum=(**theList).dataBounds.bottom;
  89.     rowNum=LAddRow(1, rowNum, theList);
  90.     SetPt(&theCell, 0, rowNum);
  91.     LSetCell(&theStr[1], theStr[0], theCell, theList);
  92. }
  93.  
  94. void MyDeleteItemFromList(ListHandle theList, short index)
  95. {
  96.     /* index is 0-based */
  97.     LDelRow(1, index, theList);
  98. }
  99.  
  100. void MyHandleMouseDownInList(WindowDataHandle theData, ListHandle theList,
  101.     EventRecord *theEvent, Boolean isUsedList)
  102. {
  103.     Point            thePoint;
  104.     
  105.     thePoint=theEvent->where;
  106.     SetPort((**theList).port);
  107.     GlobalToLocal(&thePoint);
  108.     if (LClick(thePoint, theEvent->modifiers, theList))
  109.         MyHandleDoubleClickInList(theList);
  110. }
  111.  
  112. void MyUpdateList(ListHandle theList)
  113. {
  114.     SetPort((**theList).port);
  115.     LUpdate((**theList).port->visRgn, theList);
  116.     MyDrawListBorder(theList);
  117. }
  118.  
  119. Boolean MyGetFirstSelectedCell(ListHandle theList, Cell *theCell)
  120. {
  121.     SetPt(theCell, 0, 0);
  122.     return LGetSelect(TRUE, theCell, theList);
  123. }
  124.  
  125. void MySelectOneCell(ListHandle theList, Cell theCell)
  126. {
  127.     LDoDraw(FALSE, theList);
  128.     MyDeselectAllCells(theList);
  129.     LSetSelect(TRUE, theCell, theList);
  130.     LDoDraw(TRUE, theList);
  131.     MyUpdateList(theList);
  132. }
  133.  
  134. void MyMakeCellVisible(ListHandle theList, Cell theCell)
  135. {
  136.     Rect            visibleRect;
  137.     short            dCols, dRows;
  138.     
  139.     visibleRect=(**theList).visible;
  140.     if (!PtInRect(theCell, &visibleRect))
  141.     {
  142.         dCols=dRows=0;
  143.         if (theCell.h>visibleRect.right-1)
  144.             dCols=theCell.h-visibleRect.right+1;
  145.         else if (theCell.h<visibleRect.left)
  146.             dCols=theCell.h-visibleRect.left;
  147.         else if (theCell.v>visibleRect.bottom-1)
  148.             dRows=theCell.v-visibleRect.bottom+1;
  149.         else if (theCell.v<visibleRect.top)
  150.             dRows=theCell.v-visibleRect.top;
  151.         LScroll(dCols, dRows, theList);
  152.     }
  153. }
  154.  
  155. void MyDeselectAllCells(ListHandle theList)
  156. {
  157.     Cell            nextSelectedCell;
  158.     
  159.     if (MyGetFirstSelectedCell(theList, &nextSelectedCell))
  160.     {
  161.         LDoDraw(FALSE, theList);
  162.         while (LGetSelect(TRUE, &nextSelectedCell, theList))
  163.         {
  164.             LSetSelect(FALSE, nextSelectedCell, theList);
  165.         }
  166.         LDoDraw(TRUE, theList);
  167.     }
  168. }
  169.  
  170. void MyClearAllCells(ListHandle theList)
  171. {
  172.     LDelRow(0, 0, theList);
  173. }
  174.  
  175. void MyGetCellData(ListHandle theList, Cell theCell, Str255 theName)
  176. {
  177.     short            len;
  178.     
  179.     len=63;
  180.     LGetCell(&theName[1], &len, theCell, theList);
  181.     theName[0]=len;
  182. }
  183.  
  184. void MyHandleDoubleClickInList(ListHandle theList)
  185. {
  186.     HandleError(DoTheDemoFade(theList), FALSE, FALSE);
  187. }
  188.